package com.zhiyi.app.aop;

import com.zhiyi.app.annotation.ZhiYiLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
@Aspect
public class LogAop {
    @Autowired
    private HttpSession session;

    @Autowired
    private HttpServletRequest request;

    @Pointcut("@annotation(log)")
    public void cut( ZhiYiLog log){
    }

    @AfterReturning("cut(log)")
    public void after(JoinPoint point, ZhiYiLog log){
//        日志信息
        String l=log.value();
        System.out.println("ip:"+request.getRemoteAddr()+"日志:"+l);
    }

}
